package com.eight.homepage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.eight.common.pojo.CrmBanner;
import com.eight.common.utils.OssUtil;
import com.eight.common.vo.Result;
import com.eight.homepage.service.CrmBannerService;
import com.eight.homepage.vo.CrmBannerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;


/**
 * @author 向文豪
 * @program: eight-education-parent
 * @description:
 * @date 2023/5/27 19:51
 */
@RestController
@RequestMapping("/home/banner")
@Api(tags = "轮播图")
public class CrmBannerController {
    @Autowired
    private CrmBannerService crmBannerService;

    @Autowired
    private OssUtil ossUtil;

    @PostMapping("/getAllBanner/{currentPage}/{pageSize}")
    @ApiOperation("分页查询轮播图")
    public Result getAllBanner(@PathVariable Integer currentPage,
                               @PathVariable Integer pageSize,
                               @RequestBody CrmBannerVo crmBannerVo){
        Page<CrmBanner> page = crmBannerService.findPage(currentPage, pageSize, crmBannerVo);
        return Result.success(page);
    }

    @PostMapping("/changeStatus/{id}/{isDisable}")
    @ApiOperation("改变状态")
    public Result changeStatus(@PathVariable String id, @PathVariable String isDisable){
        int i = crmBannerService.updateStatus(id, isDisable);
        return Result.success();
    }

    @PostMapping("/deleteBanner")
    @ApiOperation("删除轮播图")
    public Result deleteBanner (@RequestBody CrmBanner id){
      int i =  crmBannerService.delete(id);
      return Result.success();

    }

    @PostMapping("/uploadMsg")
    @ApiOperation("")
    public String uploadMsg(@PathParam("file") MultipartFile file){

        String path = OssUtil.uploadFile(file);
        return path;


    }

    @PostMapping("/addBanner")
    @ApiOperation("添加轮播图")
    public Result addBanner(@RequestBody CrmBanner crmBanner){
       int i =  crmBannerService.add(crmBanner);

        return Result.success();
    }
}
